using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Edge.Business.Domain.Application;
using Edge.Common.Services;
using Edge.OAuth;
using Edge.WebCode;
using Shop.Business.Domain.Customers;
using Shop.Web.AppCode;

namespace Shop.Web.Controls
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            phLogin.Visible = Locator.GetService<IContextObjects>().Get<CustomerHolder>() == null;
            if (!phLogin.Visible)
            {
                phUser.Visible = true;
                lblLogin.Text = Locator.GetService<IContextObjects>().Get<CustomerHolder>().Object.FullName;
            }
            
            base.OnPreRender(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            phUser.Visible = false;
            phLogin.Visible = Locator.GetService<IContextObjects>().Get<CustomerHolder>() == null;
            if (!phLogin.Visible)
            {
                phUser.Visible = true;
                lblLogin.Text = Locator.GetService<IContextObjects>().Get<CustomerHolder>().Object.FullName;
            }
        }
        protected string GetVkUrl()
        {
//            OAuth2 vk = new OAuth2(ConfigurationManager.AppSettings["VKApi"], ConfigurationManager.AppSettings["VKApiKey"], ShopBasePage.AuthUrl, ShopBasePage.TokenUrl, ShopBasePage.ReturnUrl);
//            return vk.GetAuthCode(new Dictionary<string, string>() { { "display", "popup" } });
            return "VK.aspx";
        }

//        protected void btLogin_Click(object sender, EventArgs e)
//        {
//            BaseMaster.Login<Customer, int>(tbLogin.Text, tbPasswd.Text);
//        }
//        protected void btLogout_Click(object sender, EventArgs e)
//        {
////            Locator.GetService<IContextObjects>().Set<UserHolder>(null);
////            Locator.GetService<IContextObjects>().Set<PersonHolder>(null);
//            Response.Redirect("Default.aspx");
//            //    Response.Redirect(Page.Request.Url.AbsoluteUri);
//        }
    }
}